﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nonocast.Scheduling {
	public class ScheduleImpl<T> : Schedule<T> {
		public List<TaskRule<T>> TaskRules { get { return taskrules; } }

		public void Add(TaskRule arg) {
			this.Add(arg.Cast<T>());
		}

		public void Add(TaskRule<T> arg) {
			taskrules.Add(arg);
			taskrules.Select((p, i) => { p.Priority = i + 1; return p; }).ToList();
		}

		public void Remove(TaskRule<T> arg) {
			taskrules.Remove(arg);
			taskrules.Select((p, i) => { p.Priority = i + 1; return p; }).ToList();
		}

		public IEnumerator<TaskRule<T>> GetEnumerator() {
			return taskrules.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return this.GetEnumerator();
		}

		public TaskRule<T> this[int index] {
			get { return taskrules[index]; }
		}

		protected List<TaskRule<T>> taskrules = new List<TaskRule<T>>();
	}
}
